#!/usr/bin/python
# -*- coding: utf-8 -*-
import unittest, time, find_file, send_mail
# from HTMLTestRunner import HTMLTestRunner
from package.HTMLTestRunner import HTMLTestRunner

if __name__ == "__main__":
    test_dir = "./test_case"
    test_report = "./report"
    discover = unittest.defaultTestLoader.discover(test_dir, pattern="test_*.py")
    now = time.strftime('%Y_%m_%d-%H_%M_%S ')
    filename = "./report/" + now + "result.html"

    #定义报告存放路径
    fp = open(filename, "wb")
    #定义测试报告
    runner = HTMLTestRunner(stream=fp,
                            title="百度搜索测试报告",
                            description="用例执行情况: ")
    #运行测试用例
    runner.run(discover)
    #关闭报告文件
    fp.close()

    #调取获取最新测试报告
    new_report = find_file.find_file(test_report)

    #调取通过邮件发送测试报告
    send_mail.send_mail(new_report)